package chat.message;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class MessageHistoryManager {
    private static final int HISTORY_SIZE = 5;
    private static Queue<ChatMessage> history = new ConcurrentLinkedQueue<ChatMessage>();


    public static List<ChatMessage> getRecentMessages() {
        return new ArrayList<ChatMessage>(history);
    }

    public static void addMessage(ChatMessage message) {
        history.add(message);
        if (history.size() > HISTORY_SIZE) {
            history.remove();
        }
    }
}
